<?php
namespace Cyfy\Modules\FastLogin;

use \Cyfy\Modules\Users\Current;

/**
 * Fast login module
 *
 * @author Dandelion
 * @version 0.1
 */
class Module extends \Cyfy\Module
{
	/**
	 * Blocks
     *
     * @param   string    Block ID
     * @return  string
     */
	static function blocks($name = '')
	{
        $output = "<h3><span>" . self :: t(130) . "</span></h3>";
		if($name != '')
		{
			// LOGIN FORM
			if(Current :: $uid == 0 || \Cyfy\Blocks::$forcedShow)
			{
                return $output . self :: loginBlock();
			}
            // LOGGED USER INFO
            return $output . self :: loggedUserInfo();
		}	
        // LIST OF BLOCKS
        return array("login"=>self :: t(50));
	}  
    
    /**
     * Returns custom login form.
     * @return string HTML form
     */    
    static private function loginBlock()
    {
       $form = new Forms\Login();
                
        $o = new \Cyfy\Modules\Objects\Overlay('fastLogin');
        $o -> setTitle("<p>" . self :: t(60) . "</p>", \Cyfy\Cyfy ::  getPath('user/login'));
        $o -> setData("<h2>" . self :: t(70) . "</h2>\n\n" . $form -> show());
        
        return $o -> show();
    }
    
    /**
     * Returns user information.
     * @return string HTML content
     */    
    static private function loggedUserInfo()
    {
        // fixes name
        $name = strtr(Current :: $name, array(" " => "&nbsp;"));
        
        $output = "<p><span class=\"user\">" . self :: t(101, array("<a href=\"" . \Cyfy\Cyfy ::  getPath('user'). "\"><strong>" . $name . "</strong></a>")) . "</span></p> ";
        $output .= "<p><a href=\"" . \Cyfy\Cyfy ::  getPath('user/settings') . "\" class=\"settings\">" . self :: t(110) . "</a> ";
        $output .= "<a href=\"" . \Cyfy\Cyfy ::  getPath('user/logout')  . "\" class=\"logout\">" . self :: t(120) . "</a></p>";
        return $output;
    }
}